package com.example.xinli.controller;

import com.example.xinli.domain.dto.EvalDto;
import com.example.xinli.domain.dto.InquiryResultDto;
import com.example.xinli.service.IInquiryService;
import com.example.xinli.domain.vo.ResponseBean;
import com.example.xinli.utils.TokenUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.el.parser.Token;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@Slf4j
@RequestMapping("/inquiry")
public class InquiryController{

    @Autowired
    private IInquiryService inquiryService;

    // 根据阶段获取问卷题目，例如2-pre
    @RequestMapping("/getAll")
    @ApiOperation("根据阶段获取问卷")
    @ResponseBody
    public ResponseBean getQuestion(@RequestParam("position") String pos) {
        return inquiryService.getInquiryByPos(pos);
    }

    @RequestMapping("/submit")
    @ApiOperation("提交问卷结果")
    @ResponseBody
    public ResponseBean submitResult(HttpServletRequest request,@RequestBody InquiryResultDto[] inquiryResultDto) {
        String id=TokenUtil.getUserId(request);
        return inquiryService.submitInquiry(id,inquiryResultDto);
    }

    @RequestMapping("/eval")
    @ApiOperation("提交看法")
    @ResponseBody
    public ResponseBean submitEval(HttpServletRequest request,@RequestBody EvalDto evalDto) {
        String id=TokenUtil.getUserId(request);
        return inquiryService.submitEval(id,evalDto);
    }


}

